<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>测试服务器推送</title>
    <script language="javascript" type="text/javascript">
        var ws;
        $(document).ready(function(){
            var output = $("#output");
            var uri = "ws://localhost:80/websocket";
            ws = new WebSocket(uri);
            ws.onopen = function (evt) {
                output.append("Connected !").append("<p/>");
                ws.send("REAL_TIME");
            };
            ws.onmessage = function (evt) {
                output.append("Received message: " + evt.data).append("<p/>");
//                echo_websocket.close();
            };
            ws.onerror = function (evt) {
                output.append('<span style="color: red;">ERROR:</span>' + evt.data).append("<p/>");
                ws.close();
            };

        });

    </script>
</head>
<body>
<h1>Echo Server</h1>
<div id="output"></div>
</body>
</html>
